package zyl.spring.boot.branch.test.lamdba;

import org.junit.Test;

/**
 * LambdaTest2类说明:
 *
 * @author z.y.l
 * @version v1.0
 * @date 2020-09-15
 */
public class LambdaTest2 {
    static class Math{
        private static Object execute(Integer... integers){
            System.out.println("Math (:");
            Integer sum = 0;
            for (Integer n:integers){
                sum += n;
            }
            return sum;
        }
    }
    interface Executor{
        Object execute(Integer... is);
    }
    private Object runExecute(Executor executor,Integer... as){
        System.out.println("runExecute (:");
        return executor.execute(as);
    }
    @Test
    public void test(){
        Integer[] ts = {1,2,3};
        //lambda的三种使用方式
        System.out.println("-----");
        System.out.println(runExecute(Math::execute,ts));
        System.out.println("-----");
        System.out.println(runExecute(gs -> Math.execute(gs), ts));
        System.out.println("-----");
        System.out.println(runExecute((Integer... ns) -> {
            System.out.println("+++");
            return ns[0]+ns[1]+ns[2];
            }, ts));
    }
}
